package ma.ensao.evalmetrics.util.javaProjects;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

/*
* Calcule la metrique AHF
*/
public class AHFMetric {
	File sourceFile;
	double ahf= 0;
	double nbAhf = 0;
	
	
	
	public double getNbAhf() {
		return nbAhf;
	}
	public void setNbAhf(double nbAhf) {
		this.nbAhf = nbAhf;
	}
	public double getAhf() {
		return ahf;
	}
	public void setAhf(double ahf) {
		this.ahf = ahf;
	}
	public AHFMetric(File file) throws FileNotFoundException, IOException{
		setSourceFile(file);
		JavaMethodsAttributes JM= new JavaMethodsAttributes(sourceFile);
		JM.setSourceFile(sourceFile);
		JM.countAttributes();
		JM.countPrivateAttributes();
		// Calcule AHF pour tout les classes
		double nmbre=0;
		nbAhf = 0;
		for (int i = 0; i < JM.getNumberClasses(); i++) {
			if (JM.getNumberPrivateAttributes()[i]==0 || JM.getNumberAttributes()[i]==0){
				nmbre=0;
				ahf +=nmbre;
			}else{
				nmbre =(double) JM.getNumberPrivateAttributes()[i]/JM.getNumberAttributes()[i];
				ahf +=nmbre; 
			}
			nbAhf += JM.getNumberPrivateAttributes()[i];
		}
		// Calcul la moyenne de AHF
		System.out.println("ahff"+ahf);
		setAhf(ahf/JM.getNumberClasses());
		setNbAhf(nbAhf);
	}
	public File getSourceFile() {
		return sourceFile;
	}
	public void setSourceFile(File sourceFile) {
		this.sourceFile = sourceFile;
	}
}
